package com.bai.base.exceptionHandler;


import com.bai.utils.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

//全局异常
@ControllerAdvice
public class GlobalExceptionHandler {

    //全局异常
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public R error(Exception e){
        e.printStackTrace();
        return R.erro().message("执行了全局异常处理");
    }

    //特点异常
    @ExceptionHandler(ArithmeticException.class)
    @ResponseBody
    public R error(ArithmeticException e){
        e.printStackTrace();
        return R.erro().message("执行了ArithmeticException异常处理");
    }

    //自定义异常
    @ExceptionHandler(BaiException.class)
    @ResponseBody
    public R error(BaiException e){
        e.printStackTrace();
        return R.erro().code(e.getCode()).message(e.getMsg());
    }
}
